package com.baturu.vin.hyundai.dal.dao;

import com.baturu.vin.hyundai.dal.entity.SEPCHyundaiSubGroupEntity;
import com.baturu.vin.hyundai.dto.HyundaiKiaPartsMappingDTO;
import com.baturu.vin.hyundai.dto.HyundaiKiaVehicleDTO;
import com.baturu.vin.hyundai.dto.KiaPartsDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

public interface KiaPartsDAO {

    @Select({"<script>" +
            "select distinct parts_id,finalPartsName finalPartName,groupName,classify,crnm,bpno,startTime,endTime,finalPartsCode,dealFinalPartsNote finalPartsNote,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,dealVehicleCode vehicleCode,count,imgX,imgY " +
            "from hyundai_parts " +
            "where bpno = #{bpno} and finalPartsCode in " +
            "<foreach item='item' index='index' collection='partsCodes' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>"})
    List<KiaPartsDTO> queryByBpnoAndPartsCode(@Param("bpno") String bpno, @Param("partsCodes") Collection<String> partsCodes);

    @Select({"<script>" +
            "select distinct parts_id, finalPartsName finalPartName,groupName,classify,crnm,bpno,startTime,endTime,finalPartsCode,dealFinalPartsNote finalPartsNote,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,dealVehicleCode vehicleCode,count,imgX,imgY,epcRemark " +
            "from hyundai_parts " +
            "where  parts_id in " +
            "<foreach item='item' index='index' collection='mappings' open='(' separator=',' close=')'>" +
            "#{item.partsId}" +
            "</foreach>" +
            "</script>"})
    List<KiaPartsDTO> queryByVinAndPartsMapping(@Param("mappings") Collection<HyundaiKiaPartsMappingDTO> mappings);

    @Select({"<script>" +
            "select distinct parts_id,finalPartsName finalPartName,groupName,classify,crnm,bpno,startTime,endTime,finalPartsCode,dealFinalPartsNote finalPartsNote,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,dealVehicleCode vehicleCode,count,imgX,imgY " +
            "from hyundai_parts " ,
            "where bpno = #{bpno} and finalPartsCode like '${partsCode}%'" ,
            "</script>"})
    List<KiaPartsDTO> queryByBpnoAndPartsCodeByPreFive(@Param("bpno") String bpno, @Param("partsCode") String partsCodes);

    @Select({"<script>" +
            "select distinct parts_id,finalPartsName finalPartName,groupName,classify,crnm,bpno,startTime,endTime,finalPartsCode,dealFinalPartsNote finalPartsNote,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,dealVehicleCode vehicleCode,count,imgX,imgY " +
            "from hyundai_parts_en " ,
            "where bpno = #{bpno} and finalPartsCode like '${partsCode}%'" ,
            "</script>"})
    List<KiaPartsDTO> queryByBpnoAndPartsCodeByPreFiveEn(@Param("bpno") String bpno, @Param("partsCode") String partsCodes);

    @Select({"<script>" +
            "select distinct parts_id,finalPartsCode,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,count,imgX,imgY " +
            "from hyundai_parts " +
            "where finalPartsCode in " +
            "<foreach item='item' index='index' collection='partsCodes' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>"})
    List<KiaPartsDTO> queryByPartsCode(@Param("partsCodes") Collection<String> partsCodes);

    @Select({"<script>SELECT distinct parts_id,epcRemark,finalPartsName finalPartName,crnm,bpno,startTime,endTime,finalPartsCode,dealFinalPartsNote finalPartsNote,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,dealVehicleCode vehicleCode,count,imgX,imgY",
            " FROM hyundai_parts",
            "WHERE bpno= #{dto.bpno}",
            "AND groupcode = #{groupDTO.groupCode}",
            "AND imgX = #{groupDTO.imageX}",
            "AND imgY = #{groupDTO.imageY}",
            "</script>"})
    List<KiaPartsDTO> queryHyundaiPartsByGroup(@Param("groupDTO") SEPCHyundaiSubGroupEntity sepcHyundaiSubGroupEntity, @Param("dto") HyundaiKiaVehicleDTO analyseResult);

    @Select({"<script>SELECT distinct parts_id,epcRemark,finalPartsName finalPartName,crnm,bpno,startTime,endTime,finalPartsCode,dealFinalPartsNote finalPartsNote,groupNumber,groupCode,finalPartsImageUrl,finalPartsImageX,finalPartsImageY,finalPartsImageOffsetX,finalPartsImageOffsetY,dealVehicleCode vehicleCode,count,imgX,imgY",
            " FROM hyundai_parts_en",
            "WHERE bpno= #{dto.bpno}",
            "AND groupcode = #{groupDTO.groupCode}",
            "AND imgX = #{groupDTO.imageX}",
            "AND imgY = #{groupDTO.imageY}",
            "</script>"})
    List<KiaPartsDTO> queryHyundaiPartsByGroupEn(@Param("groupDTO") SEPCHyundaiSubGroupEntity sepcHyundaiSubGroupEntity, @Param("dto") HyundaiKiaVehicleDTO analyseResult);
}